﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace Thallo {
    public sealed class MethodHandler : IMethodHandler {
        IMethodHandler _before;

        internal MethodHandler(Type before) {
            if (before != null) {
                _before = (IMethodHandler)Activator.CreateInstance(before);
            }
        }

        public MethodHandler(IMethodHandler before) {
            _before = before;
        }

        public bool BeforeInvoke(System.Reflection.MethodBase mi, IEnumerable inputs) {
            if (_before != null) {
                if (_before.BeforeInvoke(mi, inputs))
                    return true;
                else
                    return false;
            }
            return true;
        }

        public bool AfterInvoke(System.Reflection.MethodBase mi, IEnumerable inputs) {
            if (_before != null) {
                if (_before.AfterInvoke(mi,inputs))
                    return true;
                else
                    return false;
            }
            return true;
        }
    }
}
